package im.dario.imy;

import java.util.Collection;

import com.google.wave.api.AbstractRobotServlet;
import com.google.wave.api.Event;
import com.google.wave.api.EventType;
import com.google.wave.api.RobotMessageBundle;
import com.google.wave.api.Wavelet;

@SuppressWarnings("serial")
public class ImYServlet extends AbstractRobotServlet {

	@Override
	public void processEvents(RobotMessageBundle bundle) {
		for (Event e : bundle.getEvents()) {
			Wavelet wave = e.getWavelet();

			if (e.getType().equals(EventType.WAVELET_SELF_ADDED)
					|| e.getType().equals(
							EventType.WAVELET_PARTICIPANTS_CHANGED)) {
				Collection<String> participants = wave.getParticipants();

				if (!participants.contains("im-yang@appspot.com")) {
					wave.addParticipant("im-yang@appspot.com");
				}
			}
		}
	}
}
